package com.newcapec.modules.pass.controller;

import com.newcapec.common.utils.PageUtils;
import com.newcapec.common.utils.R;
import com.newcapec.modules.pass.entity.WhiteListContentEntity;
import com.newcapec.modules.pass.service.WhiteListContentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 黑白名单内容
 *
 * @author steven
 * @email wangsen127@163.com
 * @date 2022-01-17 10:45:52
 */
@RestController
@RequestMapping("pass/whitelistcontent")
public class WhiteListContentController {
    @Autowired
    private WhiteListContentService whiteListContentService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("pass:whitelistcontent:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = whiteListContentService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息：废弃
     */
    @Deprecated
    @GetMapping("/info/{id}")
    @RequiresPermissions("pass:whitelistcontent:info")
    public R info(@PathVariable("id") Long id){
		WhiteListContentEntity whiteListContent = whiteListContentService.getById(id);

        return R.ok().put("whiteListContent", whiteListContent);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("pass:whitelistcontent:save")
    public R save(@RequestBody WhiteListContentEntity whiteListContent){
		whiteListContentService.save(whiteListContent);

        return R.ok();
    }

    /**
     * 批量保存
     */
    @PostMapping("/saveBatch")
    @RequiresPermissions("pass:whitelistcontent:save")
    public R saveBatch(@RequestBody WhiteListContentEntity whiteListContent){
        whiteListContentService.saveBatch(whiteListContent);

        return R.ok();
    }

    /**
     * 修改：废弃
     */
    @Deprecated
    @PutMapping("/update")
    @RequiresPermissions("pass:whitelistcontent:update")
    public R update(@RequestBody WhiteListContentEntity whiteListContent){
		whiteListContentService.updateById(whiteListContent);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("pass:whitelistcontent:delete")
    public R delete(Long[] ids){
		whiteListContentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}
